package com.logicwin.RobotTravel.Navigate;

import java.util.List;

import com.logicwin.RobotTravel.Main;
import com.logicwin.RobotTravel.Navigate.messages.EventWifiScanResult;
import com.logicwin.RobotTravel.Services.Impl.ServiceManager;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;
import android.util.Log;
import android.widget.Toast;

public class WifiScanReceiver extends BroadcastReceiver {
	private static final String TAG = "WiFiScanReceiver";
	private String mSSID;
	private String mBSSID;
	private int mNetworks;
	/* private WifiManager mWifi; */
	private ScreenNavigateImpl mImpl;

	public WifiScanReceiver(ScreenNavigateImpl impl) {
		super();
		mImpl = impl;
	}

	public String getBSSID() {
		return mBSSID;
	}

	public String getSSID() {
		return mSSID;
	}

	public int getNetworks() {
		return mNetworks;
	}

	@Override
	public void onReceive(Context c, Intent intent) {
		List<ScanResult> results = mImpl.getWifiManager().getScanResults();
		mImpl.postEvent(new EventWifiScanResult(mImpl, results));
		/*
		 * ScanResult bestSignal = null;
		 * 
		 * for (ScanResult result : results) {
		 * if(ServiceManager.getPositoinService().checkMacAddr(result.BSSID) ==
		 * false) continue; if (bestSignal == null ||
		 * WifiManager.compareSignalLevel(bestSignal.level, result.level) < 0)
		 * bestSignal = result; } if(bestSignal == null) { mSSID = null; mBSSID
		 * = null; mNetworks = 0; return; }
		 * 
		 * mSSID = bestSignal.SSID; mBSSID = bestSignal.BSSID; mNetworks =
		 * results.size(); String message =
		 * String.format("%s networks found. %s is the strongest. level is "
		 * +bestSignal.level, results.size(), bestSignal.BSSID);
		 * Toast.makeText(Main.getMainActivity(), message,
		 * Toast.LENGTH_LONG).show();
		 * 
		 * Log.d(TAG, "onReceive() message: " + message);
		 */
	}
}
